#!/bin/sh

echo "[Info] Creating Release Package"

foldername="sea-archiver"

# Check if sea-archiver folder exists and remove it if it does
if [ -d "${foldername}" ]; then
    rm -rf "${foldername}"
    echo "[Info] Old release folder <${foldername}> deleted."
else
    echo "[Info] Folder \"${foldername}\" does not exist, skipping deletion."
fi

mkdir -p "./${foldername}"

# Wait for npm to run build command
echo "[Info] Waiting for npm build..."
npm run build > /dev/null

# Copy files to the new SeaArchiver folder
echo "[Info] Copying files to ${foldername}..."

cp App_SeaArchiver.py "./${foldername}/"
cp App_setting.py "./${foldername}/"
cp App_preflight.py "./${foldername}/"
cp -r service "./${foldername}/service"
cp -r WebBackend "./${foldername}/WebBackend"
cp version.json "./${foldername}/"

chmod +x "./${foldername}/service/init.sh"


echo "[Info] Copying completed."